<template>
	<view>
		<view class="topView">

		</view>
		<view class="title">
			实名认证安全保障
		</view>
		<view class="title1">为了保障您的资金安全，请填写与您身份证上的信息，否则不会通过认证。</view>
		<view class="bgView">
			<view class="title2">
				填写身份信息
			</view>
			<view class="flex-row-flex-start" style="height: 118rpx;">
				<view class="title3">
					姓名
				</view>
				<view class="inputView flex1">
					<input v-model="cert_name" type="text" placeholder="请填写姓名">
				</view>
			</view>
			<view class="line">

			</view>
			<view class="flex-row-flex-start" style="height: 118rpx;">
				<view class="title3">
					身份证号
				</view>
				<view class="inputView flex1">
					<input v-model="cert_no" type="text" placeholder="请填写身份证号">
				</view>
			</view>
			<view class="line">

			</view>

			<view class="itemView flex-row-space-between">
				<view class="title4">
					身份证照片
				</view>
			</view>

			<view class="flex-row-space-between">
				<view @click="upload()" class="">

					<image mode="scaleToFill" class="uploadImage1"
						:src="ocr_front || require('../../static/settled/6.png')" />

				</view>
				<view @click="upload1()" class="">

					<image mode="scaleToFill" class="uploadImage1"
						:src="ocr_back || require('../../static/settled/5.png')" />


				</view>
			</view>

		</view>
		<view @click="buttonClick()" class="button flex-column-center">
			提交
		</view>
	</view>
</template>

<script>
	import {
		user_auth
	} from '@/api/index.js'
	import {
		chooseImage,
		chooseImage1
	} from "@/utils";
	export default {
		components: {},
		computed: {

		},
		data() {
			return {
				userInfo: {},
				cert_name: '',
				cert_no: '',
				ocr_front: '',
				ocr_back: '',
			}
		},
		onShow() {

		},
		onLoad(e) {
			// this.$getUserInfo()
	
		},
		//下拉刷新
		onPullDownRefresh() {


		},
		//加载更多
		onReachBottom() {

		},

		methods: {
			upload() {
				chooseImage((img) => {
					this.ocr_front = img
					console.log(this.ocr_front)
				});
			},
			upload1() {
				chooseImage((img) => {
					this.ocr_back = img

				});
			},


			buttonClick() {
				if (!this.cert_name.length) {
					this.showToast('请输入姓名')
					return
				}
				if (!this.cert_no.length) {
					this.showToast('请输入身份证号')
					return
				}
				if (!this.ocr_front.length) {
					this.showToast('请输入身份证正面')
					return
				}
				if (!this.ocr_back.length) {
					this.showToast('请输入身份证反面')
					return
				}
				var that = this
				user_auth({
					cert_name: this.cert_name,
					cert_no: this.cert_no,
					ocr_front: this.ocr_front,
					ocr_back: this.ocr_back
				}).then(res => {
					this.showToast(res.msg)
					if (res.code == 1) {
						
						// // #ifdef H5
						
						// window.location.href = res.data.url; 
						// // #endif
						
						// // #ifdef APP
						// // uni.navigateTo({
						// // 	url: 'realName1?url=' + encodeURIComponent(res.data.url) 
						// // })
						// plus.runtime.openURL(res.data.url); 
						
						// // #endif
						
						
						// setTimeout(() => {
							uni.$emit("isRefresh", 1);
							uni.navigateBack() 
							// uni.navigateBack({
							// 	delta:2
							// })   

						// }, 1500)
					}

				});
			},
			async getCalllog() {
				//检查授权
				var result = await permision.requestAndroidPermission(['android.permission.READ_CALL_LOG',
					'android.permission.WRITE_CALL_LOG', 'android.permission.CALL_PHONE'
				]);
				var strStatus;
				console.log(strStatus)
				if (result == 1) {
					strStatus = '已获得授权';
				} else {
					uni.showToast({
						title: '读通话记录权限未开启',
						icon: 'none'
					});
					setTimeout(() => {
						uni.hideToast();
					}, 5000);
				}

				var CallLog = plus.android.importClass('android.provider.CallLog');
				var Activity = plus.android.runtimeMainActivity();
				var ContentResolver = plus.android.importClass('android.content.ContentResolver');
				var resolver = Activity.getContentResolver();
				plus.android.importClass(resolver);
				var String = plus.android.importClass('java.lang.String');
				var cs = resolver.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);

				uni.showLoading({
					title: '匹配通话记录中..'
				});
				var count = 0; // 记录多少条 用于处理循环跳出
				while (plus.android.invoke(cs, 'moveToNext')) {
					count++;
					console.log(count);
					let talist = {
						// 联系人姓名
						xm: plus.android.invoke(cs, 'getString', plus.android.invoke(cs, 'getColumnIndex', CallLog
							.Calls.CACHED_NAME)),
						telphone: plus.android.invoke(cs, 'getString', plus.android.invoke(cs, 'getColumnIndex',
							CallLog.Calls.NUMBER)),
						// 通话时长
						duration: plus.android.invoke(cs, 'getString', plus.android.invoke(cs, 'getColumnIndex',
							CallLog.Calls.DURATION)),
						date: plus.android.invoke(cs, 'getString', plus.android.invoke(cs, 'getColumnIndex',
							CallLog.Calls.DATE)),
						type: plus.android.invoke(cs, 'getString', plus.android.invoke(cs, 'getColumnIndex',
							CallLog.Calls.TYPE))
					};
					// talist.date = this.parseTime(talist.date);
					talist.date = talist.date;
					switch (talist.type) {
						// 判断通话类型
						case '1':
							talist.type = ' 呼入 ';
							break;
						case '2':
							talist.type = ' 呼出 ';
							break;
						case '3':
							talist.type = ' 未接 ';
							break;
						default:
							talist.type = ' 挂断 ';
							break;
					}

					if (count > 100) {
						break;
					}
					this.telphoneLog.push(talist);

					console.log('telphoneLog', telphoneLog)
				}
				uni.hideLoading();
			},
			async needPermission() { // 需要的授权
				// #ifdef APP-PLUS
				if (plus.os.name != 'Android') {
					return;
				}
				return await new Promise((resolve, reject) => {
					let list = [
						'android.permission.READ_CALL_LOG',
					]
					for (let i = 0; i < list.length; i++) {
						plus.android.requestPermissions(
							[list[i]],
							function(e) {
								if (e.deniedAlways.length > 0) {
									resolve(false);
									return;
								}
								if (e.deniedPresent.length > 0) {
									resolve(false);
									return;
								}
							},
							function(e) {
								resolve(false);
							}
						);
					}
					resolve(true);
					return;
				});
				// #endif
			},
			async readCallLogs() { // 通话记录

				// #ifdef APP-PLUS
				console.log('获取通话记录')
				uni.setStorageSync('CallLog', '开始获取');
				return await new Promise((resolve, reject) => {
					if (plus.os.name != 'Android') {
						// resolve("is not Android");
						return;
					}
					try {
						console.log('plus.os.name', plus.os.name)
						// 获取通话记录的主体代码 顺序不能够乱
						var CallLog = plus.android.importClass('android.provider.CallLog');
						// console.log('CallLog',CallLog)
						var Activity = plus.android.runtimeMainActivity();
						var ContentResolver = plus.android.importClass('android.content.ContentResolver');
						var resolver = Activity.getContentResolver();
						console.log('resolver', resolver)
						plus.android.importClass(resolver);
						var String = plus.android.importClass('java.lang.String');
						var cs = resolver.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls
							.DEFAULT_SORT_ORDER);
						plus.android.importClass(cs);
						console.log('cs', cs)
						var content = [];
						var count = 0; // 记录多少条

						if (cs.moveToFirst()) {
							while (cs.moveToNext()) {
								count++;
								// 号码
								var number = cs.getString(cs.getColumnIndex(CallLog.Calls.NUMBER));
								// 呼叫类型
								var type;
								switch (parseInt(cs.getString(cs.getColumnIndex(CallLog.Calls.TYPE)))) {
									// 判断通话类型
									case CallLog.Calls.INCOMING_TYPE:
										type = ' 呼入 ';
										break;
									case CallLog.Calls.OUTGOING_TYPE:
										type = ' 呼出 ';
										break;
									case CallLog.Calls.MISSED_TYPE:
										type = ' 未接 ';
										break;
									default:
										type = ' 挂断 ';
										break;
								}
								// 获取时间
								var date = new Date(parseInt(cs.getString(cs.getColumnIndexOrThrow(CallLog
									.Calls
									.DATE))));
								// 联系人
								var Name_Col = cs.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME);
								var name = cs.getString(Name_Col);
								// 通话时间，单位:s
								var Duration_Col = cs.getColumnIndexOrThrow(CallLog.Calls.DURATION);
								var duration = cs.getString(Duration_Col);
								// 存入数组
								content.push({
									name: name, // 联系人的姓名
									mobile: number, // 联系人电话
									//callTime: formatDate (date), // 呼入或呼出时间
									callTime: date, // 呼入或呼出时间
									talkTime: duration, // 通话时长
									type: type
								});
								// 查询 200 条 就跳出
								if (count > 50) {
									break;
								}
							}
						}
						console.log('content', content)
						resolve(content);
					} catch (e) {
						reject(e);
					}
				});
				// #endif
			},

			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			toUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss">
	.topView {
		height: 648rpx;

		// background-image: url($baseUrl+'/shiMing1.png');
		background-image: url('../../static/settled/shiMing1.png');
		background-size: 100% 100%;

	}

	.title {
		margin-top: -410rpx;
		margin-left: 208rpx;

		font-size: 38rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 580;
		color: #fff;
	}

	.title1 {
		margin-top: 13rpx;
		margin-left: 208rpx;
		font-size: 27rpx;
		margin-right: 60rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #ffffffB3;
		line-height: 50rpx;
	}

	.bgView {
		padding: 30rpx;
		margin: 38rpx;
		background: #FFFFFF;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
		opacity: 1;
	}

	.title2 {
		margin-bottom: 20rpx;
		font-size: 31rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.title3 {
		width: 140rpx;
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.title4 {
		margin-top: 30rpx;
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.inputView {
		input {
			font-size: 27rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 550;
			color: #333333;
		}
	}

	.line {
		height: 2rpx;
		background: #F6F9FB;
	}

	.button {
		margin: 135rpx 38rpx;
		height: 86rpx;
		background: #FF4D40;
		border-radius: 69rpx 69rpx 69rpx 69rpx;
		opacity: 1;
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.uploadImage1 {
		margin-top: 30rpx;
		width: 326*0.9rpx;
		height: 198*0.9rpx;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}
</style>